package stock.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/test")
public class TestController {

    @Value("${server.port}")
    String port;

    @RequestMapping("/hello")
    public String reduce(){
        System.out.println("访问成功：" + port);
        return "访问成功：" + port;
    }

    private static void openDoor(int n){
        boolean[] doors = new boolean[n + 1];

        for (int i = 1; i <= n; i++) {
            for (int j = i; j <= n; j += i) {
                doors[j] = !doors[j]; // 切换门的状态
            }
        }
        System.out.println("打开的门编号:");
        for (int i = 1; i <= n; i++) {
            if (doors[i]) {
                System.out.print(i + " ");
            }
        }

        int openCount = (int) Math.sqrt(n); // 计算打开的门数量
        System.out.println("\n打开的门的数量: " + openCount);
    }

    public static void main(String[] args) {
        openDoor(100);
    }

}
